// pages/common/recruitment-detail/index.js
import {getDetail} from "../../../service/Position";
import {getStorageSync} from "../../../utils/Storage";
import Toast from "@vant/weapp/toast/toast";
import Config from "../../../main.config";
Page({

    /**
     * 页面的初始数据
     */
    data: {
        pageShow: false,
        errorShow: false,
        detail: {}
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.data._options = options;
        this.getRecruitmentDetail()
    },

    /*
      * 获取招聘详情
      * */
    getRecruitmentDetail: async function () {
        try {
            let id = this.data._options.id;
            let staffId = this.data._options.staffId || "";
            let createUser = getStorageSync(Config.storage.registerInfo + ".createUser");
            Toast.loading({
                message: "加载中...",
                mask: true,
                duration: 0
            });
            let detail = await getDetail({id, createUser});
            let logoUrl = (Config.api.downLoad + "?fileId=" + detail.companyLogo) || "";
            this.setData({
                detail: {
                    id: detail.id,
                    name: detail.name,
                    salary: detail.salary,
                    city: detail.city,
                    nature: detail.nature,
                    staffName: detail.staffName,
                    staffId: staffId,
                    companyId: detail.companyId,
                    companyLogo: logoUrl,
                    companyName: detail.companyName,
                    companyIntro: detail.companyNature + "·"
                    + detail.companyScale + "·"
                    + detail.companyIndustryName,
                    schooling: detail.schooling,
                    remark: decodeURIComponent(detail.remark || ""),
                    createUser: detail.createUser,
                    collection: detail.collection,
                    rdCount: detail.rdCount
                },
                pageShow: true
            })
            Toast.clear();
        } catch (e) {
            Toast.fail("获取信息失败");
            this.setData({errorShow: true})
            console.error(e)
        }
    },

    /*
    * 更新监听
    * */
    onUpdate: function () {
        this.getRecruitmentDetail();
    },


    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})